package com.tianji.promotion;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class testJUC {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                System.out.println("Thread1"+Thread.currentThread().getName());
                Thread.sleep(1000);
                return  new Random().nextInt(100);
            }
        };
        FutureTask<Integer> futureTask = new FutureTask<Integer>(callable);
        System.out.println("Thread2"+Thread.currentThread().getName());
        new Thread(futureTask).start();
        System.out.println(futureTask.get());//get会阻塞
        System.out.println("Thread2"+Thread.currentThread().getName());
    }
}
